<template>
  <van-tabbar v-model="active" route fixed placeholder>
    <van-tabbar-item
      v-for="{ text, icon, a_icon, to } in iconList"
      :key="text"
      replace
      :to="to"
    >
      <span>{{ text }}</span>
      <template #icon="props">
        <img :src="props.active ? a_icon : icon" />
      </template>
    </van-tabbar-item>
  </van-tabbar>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      iconList: [
        {
          text: "首页",
          icon: require("../assets/images/home.svg"),
          a_icon: require("../assets/images/a_home.svg"),
          to: "/home",
        },
        {
          text: "我的",
          icon: require("../assets/images/mine.svg"),
          a_icon: require("../assets/images/a_mine.svg"),
          to: "/mine",
        },
      ],
    };
  },
  methods: {
    initToken() {
      const info = JSON.parse(localStorage.getItem("userInfo"));
      // token = info.token;
      console.log("token----->", info);
      this.iconList = [
        {
          text: "首页",
          icon: require("../assets/images/home.svg"),
          a_icon: require("../assets/images/a_home.svg"),
          to: "/home",
        }
      ]
      if (info) {
        if (info.isOrder === 1 || info.isSchedule === 1) {
          this.iconList.push({
            text: "订单",
            icon: require("../assets/images/order.svg"),
            a_icon: require("../assets/images/a_order.svg"),
            to: "/order",
          })
        }
        if (info.isPilot === 1 || info.isCompany === 1) {
          this.iconList.push({
            text: "任务",
            icon: require("../assets/images/task.svg"),
            a_icon: require("../assets/images/a_task.svg"),
            to: "/task",
          })
        }
      }
      this.iconList.push({
        text: "我的",
        icon: require("../assets/images/mine.svg"),
        a_icon: require("../assets/images/a_mine.svg"),
        to: "/mine",
      })
    },
  },
  mounted() {
    this.initToken();
  },
};
</script>
